package fhp.hlhj.giantfold.activity.cameraScan

import android.content.Intent
import android.view.LayoutInflater
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.MerchantAdp
import fhp.hlhj.giantfold.interfaces.ISellers
import fhp.hlhj.giantfold.javaBean.MerchantBean
import fhp.hlhj.giantfold.javaBean.SellersBean
import fhp.hlhj.giantfold.presenter.SellersPresenter
import kotlinx.android.synthetic.main.activity_movie_aty.*

class MerchantAty : BaseActivity(), ISellers {
    private lateinit var sellerPresenter:SellersPresenter
    private val datas=java.util.ArrayList<MerchantBean.DataBean>()
    private lateinit var merChantAdp: MerchantAdp
    override fun getContentId(): Int = R.layout.activity_movie_aty
    private var page=0
    override fun initView() {
        sellerPresenter= SellersPresenter(this)
        merChantAdp = MerchantAdp(this,datas)
        tvTitle.text=intent.getStringExtra("name")
        listView.adapter= merChantAdp
        listView.emptyView=LayoutInflater.from(this).inflate(R.layout.empty_view,null)
        val params = HttpParams()
        params.put("page",page)
        params.put("type",intent.getStringExtra("pid"))
        sellerPresenter.getMerchant(params)


    }
    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
        listView.setOnItemClickListener { parent, view, position, id ->
            val intent = Intent(this@MerchantAty, MerchantDetailAty::class.java)
            intent.putExtra("data",datas[position])
            startActivity(intent)
        }
    }
    override fun showLoading() {
        loadingDialog.show()
    }

    override fun getSellers(sellersBean: SellersBean) {
    }

    override fun getMerchant(merchantBean: MerchantBean) {
        if (merchantBean.code==200){
            datas.clear()
            datas.addAll(merchantBean.data)
            merChantAdp.notifyDataSetChanged()
        }
    }
}
